package org.xtext.ic.dsl;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.common.types.JvmDeclaredType;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;
import org.xtext.ic.dsl.iCDsl.Attribute;
import org.xtext.ic.dsl.iCDsl.Layer;
import org.xtext.ic.dsl.iCDsl.PackagePrefix;
import org.xtext.ic.dsl.iCDsl.Type;

@SuppressWarnings("all")
public class ICDslExtensions {
  
  public String packageName(final PackagePrefix pp, final Object o) {
    String _xifexpression = null;
    String _name = pp.getName();
    boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_name);
    if (_isNullOrEmpty) {
      String _layerName = this.layerName(o);
      _xifexpression = _layerName;
    } else {
      String _name_1 = pp.getName();
      String _operator_plus = StringExtensions.operator_plus(_name_1, ".");
      String _layerName_1 = this.layerName(o);
      String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, _layerName_1);
      _xifexpression = _operator_plus_1;
    }
    return _xifexpression;
  }
  
  public String layerName(final Object o) {
    String _switchResult = null;
    final Object o_1 = o;
    boolean matched = false;
    if (!matched) {
      if (o_1 instanceof Layer) {
        final Layer o_2 = (Layer) o_1;
        matched=true;
        EObject _eContainer = o_2.eContainer();
        String _layerName = this.layerName(_eContainer);
        String _name = o_2.getName();
        String _concatPath = this.concatPath(_layerName, _name);
        _switchResult = _concatPath;
      }
    }
    if (!matched) {
      if (o_1 instanceof EObject) {
        final EObject o_3 = (EObject) o_1;
        matched=true;
        EObject _eContainer_1 = o_3.eContainer();
        String _layerName_1 = this.layerName(_eContainer_1);
        _switchResult = _layerName_1;
      }
    }
    if (!matched) {
      if (o_1 instanceof JvmDeclaredType) {
        final JvmDeclaredType o_4 = (JvmDeclaredType) o_1;
        matched=true;
        String _layerName_2 = this.layerName(o_4);
        _switchResult = _layerName_2;
      }
    }
    if (!matched) {
      _switchResult = null;
    }
    return _switchResult;
  }
  
  public String concatPath(final String prefix, final String suffix) {
    String _xifexpression = null;
    boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(prefix);
    if (_isNullOrEmpty) {
      _xifexpression = suffix;
    } else {
      String _operator_plus = StringExtensions.operator_plus(prefix, ".");
      String _operator_plus_1 = StringExtensions.operator_plus(_operator_plus, suffix);
      _xifexpression = _operator_plus_1;
    }
    return _xifexpression;
  }
  
  public StringConcatenation typeDeclaration(final Attribute a) {
    StringConcatenation _builder = new StringConcatenation();
    {
      boolean _isMany = a.isMany();
      if (_isMany) {
        _builder.append("List<");
        Type _type = a.getType();
        String _name = _type.getName();
        _builder.append(_name, "");
        _builder.append(">");} else {
        Type _type_1 = a.getType();
        String _name_1 = _type_1.getName();
        _builder.append(_name_1, "");
      }
    }
    return _builder;
  }
  
  public StringConcatenation variable(final Attribute a) {
    StringConcatenation _builder = new StringConcatenation();
    StringConcatenation _typeDeclaration = this.typeDeclaration(a);
    _builder.append(_typeDeclaration, "");
    _builder.append(" ");
    String _name = a.getName();
    _builder.append(_name, "");
    return _builder;
  }
}